package com.xudow.app.newui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xudow.app.Config;
import com.xudow.app.R;
import com.xudow.app.newui.fragment.ToolKitFragment;
import com.xudow.app.util.ImageUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 作者：LownChen on 2016/6/2 13:22
 */
public class StudentHadapter extends BaseAdapter {
    private Context context;
    private List<ToolKitFragment.Student> data;

    public StudentHadapter(Context context, List<ToolKitFragment.Student> data) {
        this.context = context;
        this.data = data;
    }

    public void setData(List<ToolKitFragment.Student> data){
        this.data=data;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if (null==data)
            return 0;
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        ViewHolder holder;
        if (null==v){
            holder=new ViewHolder();
                v=View.inflate(context, R.layout.item_myfragment_child_hlist,null);
            holder.ico=(CircleImageView)v.findViewById(R.id.child_ico_iv);
            holder.name=(TextView)v.findViewById(R.id.child_name_tv);
            holder.flage=(ImageView)v.findViewById(R.id.selected_flag_iv);
            v.setTag(holder);
        }else
            holder=(ViewHolder)v.getTag();
            ToolKitFragment.Student student= data.get(position);
            holder.name.setText(student.item.getName());
            if (student.isselect) {
                holder.flage.setVisibility(View.VISIBLE);
                holder.name.setTextColor(Color.parseColor("#55c11f"));
                v.setBackgroundColor(Color.WHITE);
            }else {
                holder.flage.setVisibility(View.INVISIBLE);
                holder.name.setTextColor(Color.parseColor("#393939"));
                v.setBackgroundColor(Color.parseColor("#f9f9f9"));

            }
            //加载图片
            String url = String.format("%s%s?name=%s", Config.BASE_URL, Config.IMAGE_LOAD_URL, student.item.getPhotoPath());
            ImageUtils.loadImage(context, holder.ico, url, R.mipmap.btn_profile_default_head_img);
        return v;
    }

    class ViewHolder{
        CircleImageView ico;
        TextView name;
        ImageView flage;
    }
}
